$(function(){
    init_create_data();
});
function init_create_data (){
    $.post(ctx+"SalePhone/getAllCphoneTask",function (r) {
        var data = r.msg;
        $("#contentTask").empty();$("#contentTaskOver").empty();
        if (data.length >0 ){
            $.each(data,function(index,val){
                var title = val.spBatch;
                var status = val.spStatusFen;
                var totle = val.spLastRecord;
                var content  = "";
                if (status =="1"){
                    content =  " <div class=\"col-md-4 text-center line-height-100\">\n" +
                        "            <a href=\"#\" onclick='fenTaskPhone(this);' data='"+val.spUuid+"' data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"分配执行\"><i class=\"fa fa-sliders fa-2x m-r-15\"></i></a>\n" +
                        "            <a href=\"#\" onclick='SetTaskPhone(this);' data='"+val.spUuid+"' data-toggle=\"tooltip\" data-placement=\"bottom\"  title=\"设置\"><i class=\"fa fa-gear fa-2x  m-r-15\"></i></a>\n" +
                        "        </div>\n";
                }else{
                    content =  " <div class=\"col-md-4 text-center line-height-100\">\n" +
                        "            <a href=\"#\" onclick='SetTaskPhone(this);' data='"+val.spUuid+"' data-toggle=\"tooltip\" data-placement=\"bottom\"  title=\"设置\"><i class=\"fa fa-gear fa-2x  m-r-15\"></i></a>\n" +
                        "        </div>\n";
                }
                /** "            <a href=\"#\" onclick='DataNumPhone(this);' data='"+val.spUuid+"' data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"数据统计\"><i class=\"fa fa-bar-chart-o fa-2x  m-r-15\"></i></a>\n" +**/
                var fenpei = val.spFenName;
                var p= "";
                var phone = val.spRecordUrl;
                var num = 0;
                if (phone !=null){
                    num = phone.split(",").length
                }
                if (fenpei == "" || fenpei == null){
                    p = "<p>未分配</p><p>"+val.spCreator+"创建于"+val.spCreatetime+"</p>";
                }else{
                    p = "<p>分配给: "+fenpei+"&nbsp;&nbsp;&nbsp; 完成量:"+num+"/"+totle+"</p><p>"+val.spCreator+"创建于"+val.spCreatetime+"</p>";
                }
                var comnall ="<a href='#' onclick='selectTask(this)' data='"+val.spUuid+"'><div class=\"row box-shadow m-10 height-100\">\n" +
                    "        <div class=\"col-md-8 border-right-1\">\n" +
                    "            <h4><i class=\"fa fa-commenting-o fa-fw\"></i> "+title+"</h4>\n" +p+
                    "        </div>"+content +"</div></a>";
                if (status == "3"){
                    $("#contentTaskOver").append(comnall);
                }else{
                    $("#contentTask").append(comnall);
                }
            });
            $("[data-toggle='tooltip']").tooltip();
        } else{
            var data =  "<p class='text-center m-t-40'>\n" +
                "            <i class=\"fa fa-check-square-o fa-4x  muted\"></i>\n" +
                "            <br/><span>所有的任务已加载完成</span>\n" +
                "            </p>";
            $("#contentTask").empty().append(data);
            $("#contentTaskOver").empty().append(data);
        }
    });
}
/**创建电话任务**/
function createTask(){
    $.post(ctx+"SalePhone/loadSaleAddTask",function (r) {
        $("#diaLoadModal").empty().append(r).modal("show");
    });
}
/**查看所有的详情信息**/
function selectTask(btn){
    var uuid = $(btn).attr("data");
    $("#selectUUids").val(uuid);
    $.post(ctx+"SalePhone/loadSaleTaskDetail",function (r) {
        $("#salePhoneContent").empty().append(r);
    });
}
/**分配电话任务**/
function fenTaskPhone(btn){
    var uuid = $(btn).attr("data");
    $("#selectUUids").val(uuid);
    $.post(ctx+"SalePhone/loadSaleFenTask",function (r) {
        $("#diaLoadModal").empty().append(r).modal("show");
    });
}
/**数据统计**/
function DataNumPhone(btn){
    var uuid = $(btn).attr("data");
    $("#selectUUids").val(uuid);
    $.post(ctx+"SalePhone/loadSaleDataNum",function (r) {
        $("#diaLoadModal").empty().append(r).modal("show");
    });
}
/**设置**/
function SetTaskPhone(btn){
    var uuid = $(btn).attr("data");
    $("#selectUUids").val(uuid);
    $.post(ctx+"SalePhone/loadSaleSetPhone",function (r) {
        $("#diaLoadModal").empty().append(r).modal("show");
    });
}
